import { Component } from 'react'
import { Erroring } from '@/components/Blank'

export default class ErrorBoundary extends Component {
  static getDerivedStateFromError(error) {
    return { hasError: true }
  }

  state = {
    hasError: false
  }

  componentDidCatch(error, info) {
    // 可以在这里添加日志
    console.warn('ErrorBoundary::something error:', error, info)
  }

  handleRetry() {
    location.reload()
  }

  render() {
    return this.state.hasError ? (
      <Erroring onClick={this.handleRetry} height="80vh" />
    ) : (
      this.props.children
    )
  }
}
